<!--
 * @Descripttion: 
 * @Version: 1.0
 * @Author: wangph
 * @Date: 2021-03-31 09:46:02
 * @LastEditors: wangph
 * @LastEditTime: 2021-04-30 09:05:14
-->
{extend name="layout" /}
{block name="content"}
<div class="row">
    <div class="col-xs-12">
		<div class="box">
		<div class="box-header with-border">
			<h3 class="box-title">{$page_title}</h3>
		</div>
		<div class="box-body">
        <!-- 应用列表 -->
        <div class="data-table table-striped">
            <table class="table table-bordered table-striped table-hover">
                <thead>
                    <tr>
                        <th width="200">{:lang('备份名称')}</th>
                        <th width="80">{:lang('卷数')}</th>
                        <th width="80">{:lang('压缩')}</th>
                        <th width="80">{:lang('数据大小')}</th>
                        <th width="200" class="text-center">{:lang('备份时间')}</th>
                        <th class="text-center">{:lang('状态')}</th>
                        <th width="200" class="text-center">{:lang('操作')}</th>
                    </tr>
                </thead>
                <tbody>
                    {volist name="list" id="data"}
                        <tr>
                            <td>{$data.time|date='Ymd-His'}</td>
                            <td>{$data.part}</td>
                            <td>{$data.compress}</td>
                            <td>{$data.size|format_bytes}</td>
                            <td class="text-center">{$key}</td>
                            <td class="text-center">-</td>
                            <td class="action text-center">
                                <a class="db-import btn btn-xs btn-default btn-flat" href="{:url('import?time='.$data['time'])}"><i class="fa fa-history"></i> {:lang('还原')}</a>&nbsp;
                                <a class="ajax-get confirm btn btn-xs btn-default btn-flat" href="{:url('del?time='.$data['time'])}"><i class="fa fa-times"></i> {:lang('删除')}</a>
                            </td>
                        </tr>
                    {/volist}
                </tbody>
            </table>
        </div>
		</div>
		</div>
        <!-- /应用列表 -->
    </div>
</div>
{/block}

{block name="script"}
    <script type="text/javascript">
        $(".db-import").click(function(){
			Stars.loading();
            var self = this, code = ".";
            $.get(self.href, success, "json");
            window.onbeforeunload = function(){ return "{:lang('正在还原数据库')}"+"，"+"{:lang('请不要关闭')}"+"！" }
            return false;
        
            function success(data){
                if(data.code){
                    if(data.data.gz){
                        data.msg += code;
                        if(code.length === 5){
                            code = ".";
                        } else {
                            code += ".";
                        }
                    }
                    $(self).parent().prev().text(data.msg);
                    if(data.data.part){
                        $.get(self.href, 
                            {"part" : data.data.part, "start" : data.data.start}, 
                            success, 
                            "json"
                        );
                    }  else {
						Stars.loading('hide');
                        window.onbeforeunload = function(){ return null; }
                    }
                } else {
					Stars.notify(data.msg, 'danger');
                }
            }
        });
    </script>
{/block}